#include "WINApt_Hdr.h"


BOOL WINApt_Service_Parament(int argc,char **argv, WINAPT_SERVERCONFIG *pSt_StartlParam)
{
    LPCTSTR lpszAuthCfg = _T("./WINApt_Config/WINApt_Config.ini");

    pSt_StartlParam->nPort = GetPrivateProfileInt(_T("ServiceConfig"),_T("Port"),0,lpszAuthCfg);
    pSt_StartlParam->Threads = GetPrivateProfileInt(_T("ServiceConfig"),_T("Threads"),0,lpszAuthCfg);
    pSt_StartlParam->nDeamon = GetPrivateProfileInt(_T("ServiceConfig"),_T("AutoStart"),0,lpszAuthCfg);

    GetPrivateProfileString(_T("ServiceSql"), _T("SQLAddr"), NULL, pSt_StartlParam->st_SQLInfo.tszSQLAddr, 64, lpszAuthCfg);
    GetPrivateProfileString(_T("ServiceSql"), _T("SQLUser"), NULL, pSt_StartlParam->st_SQLInfo.tszSQLUser, 64, lpszAuthCfg);
    GetPrivateProfileString(_T("ServiceSql"), _T("SQLPass"), NULL, pSt_StartlParam->st_SQLInfo.tszSQLPass, 64, lpszAuthCfg);

    for (int i = 0;i < argc;i++)
    {
        if ((0 == _tcscmp("-h",argv[i])) || (0 == _tcscmp("-H",argv[i])))
        {
            WINApt_Service_ParamentHelp();
            return FALSE;
        }
        if ((0 == _tcscmp("-v",argv[i])) || (0 == _tcscmp("-V",argv[i])))
        {
            printf("Version：V1.1.0\n");
            return FALSE;
        }
        else if (0 == _tcscmp("-p",argv[i]))
        {
            pSt_StartlParam->nPort = _ttoi(argv[i + 1]);
        }
        else if (0 == _tcscmp("-t",argv[i]))
        {
            pSt_StartlParam->Threads = _ttoi(argv[i + 1]);
        }
        else if (0 == _tcscmp("-d",argv[i]))
        {
            pSt_StartlParam->nDeamon = _ttoi(argv[i + 1]);
        }
    }

    return TRUE;
}

void WINApt_Service_ParamentHelp()
{
    printf(_T("--------------------------启动参数帮助开始--------------------------\n"));
    printf(_T("WINAPT启动参数：程序 参数 参数值，参数是区分大小写的。如果不指定将会加载默认的ini配置文件里面的参数\n"));
    printf(_T("-h or -H：启动参数帮助提示信息\n"));
    printf(_T("-p：设置服务端口号\n"));
    printf(_T("-t：设置线程池业务处理线程个数\n"));
    printf(_T("-d：1 启用守护进程，2不启用\n"));
    printf(_T("--------------------------启动参数帮助结束--------------------------\n"));
}
